﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;


public partial class User_Shares_PasswordChange : System.Web.UI.Page
{
    protected void Page_Load( object sender, EventArgs e )
    {
       
        Lblstatus.Text = "";
    }

    protected void BtnRegister_Click( object sender, EventArgs e )
    {
        try
        {
            MembershipUser mu = Membership.GetUser(Membership.GetUser().UserName);
            //bool result = mu.ChangePassword( mu.GetPassword(), TxtnewPass.Text );
              //string Oldpassword =Membership.GetUser().ResetPassword();
            
      
           if (Membership.ValidateUser(mu.UserName.ToString().Trim(), TextBoxOldPass.Text.ToString().Trim()))
           {
               string Oldpassword = mu.ResetPassword();
               bool result = mu.ChangePassword(Oldpassword, TxtnewPass.Text);
               //mu.ResetPassword(
               if (result == true)
               {
                   
                   Lblstatus.Text = " <script>alert('.تغییر رمز با موفقیت انجام شد')</script>";
                   Response.Clear();

                   FormsAuthentication.SignOut();
               }
               else
               {
                   Lblstatus.Text = " <script>alert('.تغییر رمز با خطا مواجه شد')</script>";
               }
           }
           else
               Lblstatus.Text = " <script>alert('.رمز قبلی اشتباه وارد شده است')</script>";
        }
        catch
        {
            Lblstatus.Text = " <script>alert('.تغییر رمز با خطا مواجه شد')</script>";
        }
    }

}